﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Web.UI;

namespace Churchtoolkit.Utils.ErrorProvider
{
    public class ValidationPlaceHolderPairCollection : CollectionBase
    {
        public ValidationPlaceHolderPair this[int index]
        {
            get
            {
                return ((ValidationPlaceHolderPair)List[index]);
            }
            set
            {
                List[index] = value;
            }
        }

        public int Add(ValidationPlaceHolderPair value)
        {
            return (List.Add(value));
        }
        public int Add(IValidator validator, string placeholder, string value)
        {
            return(List.Add(new ValidationPlaceHolderPair { Placeholder = placeholder, 
                                            Validator = validator,
                                            Value = value }));
        }

        public void ReplaceAllPlaceHolders()
        {
            foreach (ValidationPlaceHolderPair validator in this)
            {
                validator.Validator.ErrorMessage = validator.Validator.ErrorMessage.Replace(validator.Placeholder, validator.Value);
            }
        }
    }
}
